/*
 * 非空判断
 */
function isNull(obj) {
	if ((obj == null) || (obj == "null") || (obj.length == 0)) {
		return true;
	} else {
		return false;
	}
}

/*
 * 带有提示信息的非空判断
 */
function isNullMsg(obj, message) {
	if(isNull(obj)){
		alert(message);
		return false;
	} else {
		return true;
	}
}


//***************************************************

//获取字符长度
function getlength(sText) {
	var svar = sText.Trim();
	sText = svar;
	var idex = 0;
	var len = 0;
	for (idx = 0; idx < sText.length; idx++) {
		var cd = sText.charCodeAt(idx);
		if (cd < 256) {
			len = len + 1;
		} else {
			len = len + 2;
		}
	}
	return len;
}


//检查是否有`~'等字符
function checkSpecChar(s) {
	for (var i = 0; i < s.length; i++) {
		var c = s.substring(i, i + 1);
		if ((c == "\\") || (c == "'") || (c == "\"")) {
			return false;
		}
	}
	return true;
}
//电话号码中只能有数字，*-()
function checkPhoneNum(s) {
	if (IsNum(s)) {
		return true;
	}
	for (var i = 0; i < s.length; i++) {
		var c = s.substring(i, i + 1);
		if (IsNum(c) == true) {
			continue;
		} else {
			if ((c == "*") || (c == "-") || (c == "(") || (c == ")")) {
				continue;
			} else {
				return false;
			}
		}
	}
	return true;
}


//去除份数中的","
function releasedot(num) {
	num = num.toString();
	var returnnum = "";
	var i = 0;
	while (i < num.length) {
		var c = num.substring(i, i + 1);
         //alert(c);
		if (c != ",") {
			returnnum = returnnum + c;
		}
		i++;
	}
	return returnnum;
}
function checkPer(num) {
	var tempNum = 0;
	for (var i = 0; i < num.length - 1; i++) {
		tempNum += parseFloat(num.substring(i, i + 1)) * (i + 1);
	}
	tempNum = tempNum + "";
	if (tempNum.substring(tempNum.length - 1) == num.substring(num.length - 1)) {
		return true;
	} else {
		return false;
	}
}

//检查身份证输入是否正确
function checkID(num) {
	if (!IsNum(num.substring(0, num.length - 1))) {
		return false;
	}
	if (num.length == 15) {
		if (!checkDate(num.substring(6, 12))) {
			return false;
		}
	} else {
		if (num.length == 18) {
			if (!checkDate(num.substring(6, 14))) {
				return false;
			}
		} else {
			return false;
		}
	}
	return true;
}


//判断num是否为格式yyyymmdd的日期
function checkDate(num) {
	var year, month, day;
	if (num.length == 6) {
		year = 19 + num.substring(0, 2);
		month = num.substring(2, 4);
		day = num.substring(4, 6);
	} else {
		if (num.length == 8) {
			year = num.substring(0, 4);
			month = num.substring(4, 6);
			day = num.substring(6, 8);
		}
	}
	if (!checkRange(year, month, day)) {
		return false;
	}
	return true;
}

//判断年月日是否在范围之内
function checkRange(pYear, pMonth, pDay) {
	days = new Array(13);
	days[1] = 31;
	days[2] = 28;
	days[3] = 31;
	days[4] = 30;
	days[5] = 31;
	days[6] = 30;
	days[7] = 31;
	days[8] = 31;
	days[9] = 30;
	days[10] = 31;
	days[11] = 30;
	days[12] = 31;
	pYear = parseInt(pYear, 10);
	pMonth = parseInt(pMonth, 10);
	pDay = parseInt(pDay, 10);
	if ((pYear % 4 == 0 && pYear % 100 != 0) || (pYear % 400 == 0)) {
		days[2] = 29;
	}
	if (pYear < 1900 || pYear > 3000) {
		return false;
	}
	if (pMonth < 1 || pMonth > 12) {
		return false;
	}
	if (pDay > days[pMonth] || pDay < 1) {
		return false;
	}
	var today = new Date();
	var tYear = today.getYear();
	if (tYear < 100) {
		tYear = 1900 + tYear;
	}
	tMonth = today.getMonth() + 1;
	tToday = today.getDate();
	if (parseFloat(pYear) > parseFloat(tYear)) {
		return false;
	} else {
		if (parseFloat(pYear) == parseFloat(tYear)) {
			if (parseFloat(pMonth) > parseFloat(tMonth)) {
				return false;
			} else {
				if (parseFloat(pMonth) == parseFloat(tMonth)) {
					if (parseFloat(pDay) > parseFloat(tToday)) {
						return false;
					}
				}
			}
		}
	}
	return true;
}
//判断年月日是否在范围之内
function checkRange_notoday(pYear, pMonth, pDay) {
	days = new Array(13);
	days[1] = 31;
	days[2] = 28;
	days[3] = 31;
	days[4] = 30;
	days[5] = 31;
	days[6] = 30;
	days[7] = 31;
	days[8] = 31;
	days[9] = 30;
	days[10] = 31;
	days[11] = 30;
	days[12] = 31;
	pYear = parseInt(pYear, 10);
	pMonth = parseInt(pMonth, 10);
	pDay = parseInt(pDay, 10);
	if ((pYear % 4 == 0 && pYear % 100 != 0) || (pYear % 400 == 0)) {
		days[2] = 29;
	}
	if (pYear < 1900 || pYear > 3000) {
		return false;
	}
	if (pMonth < 1 || pMonth > 12) {
		return false;
	}
	if (pDay > days[pMonth] || pDay < 1) {
		return false;
	}
	return true;
}



//数字判定包括浮点数
function IsNum(str) {
	var j = 0;
	var ch = "";
	str = trim(str);
	if (str.length == 0) {
		return false;
	}
	for (var i = 0; i < str.length; i++) {
		ch = str.charAt(i);
		if (ch == ".") {
			j++;
			if (j > 1) {
				return false;
			}
		} else {
			if ((parseInt(ch) + "") == "NaN") {
				return false;
			}
		}
	}
	return true;
}
//数字判定包括浮点数
function IsNum2PointNum(str) {
	var j = 0;
	var ch = "";
	var pointnum = 0;
	str = trim(str);
	if (str.length == 0) {
		return false;
	}
	for (var i = 0; i < str.length; i++) {
		ch = str.charAt(i);
		if (ch == ".") {
			j++;
			if (j > 1) {
				return false;
			}
		} else {
			if ((parseInt(ch) + "") == "NaN") {
				return false;
			}
		}
		if (j > 0) {
			pointnum++;
		}
		if (pointnum > 3) {
			return false;
		}
	}
	return true;
}
      
 //判定nav小数3位
function IsNum3PointNum(str) {
	var j = 0;
	var ch = "";
	var pointnum = 0;
	str = trim(str);
	if (str.length == 0) {
		return false;
	}
	for (var i = 0; i < str.length; i++) {
		ch = str.charAt(i);
		if (ch == ".") {
			j++;
			if (j > 1) {
				return false;
			}
		} else {
			if ((parseInt(ch) + "") == "NaN") {
				return false;
			}
		}
		if (j > 0) {
			pointnum++;
		}
		if (pointnum > 4) {
			return false;
		}
	}
	return true;
}    
      
  
//整数判定
function isInt(val) {
	for (i = 0; i < val.length; i++) {
		p = val.charAt(i);
		if (p < "0" || p > "9") {
			if (i == 0 && p == "-") {
				continue;
			} else {
				return false;
			}
		}
	}
	return true;
}

//左去空
function ltrim(str) {
	str = str + "";
	if (str.length == 0) {
		return str;
	}
	var i = 0;
	while ((i < str.length) && (str.substring(i, i + 1) == " ")) {
		i++;
	}
	return str.substring(i, str.length);
}
//右去空
function rtrim(instr) {
	instr = instr + "";
	var last_space;
	var ret;
	last_space = instr.length;
	while ((instr.charAt(last_space - 1) == " ") && (last_space > 0)) {
		last_space--;
	}
	if (last_space == 0) {
		return "";
	} else {
		return instr.substring(0, last_space);
	}
}
//去空
function trim(s) {
	return ltrim(rtrim(s));
}

       //判断输入是否有'@'
function isEmail(s) {
	if (s.length < 5) {
		return false;
	}
	if ((s.charAt(0) == "@") || (s.charAt(0) == ".")) {
		return false;
	}
	if ((s.charAt(s.length - 1) == "@") || (s.charAt(s.length - 1) == ".")) {
		return false;
	}
	var count = 0;
	var hasdot = false;
	for (var i = 0; i < s.length; i++) {
		if (s.charAt(i) == "@") {
			count++;
		} else {
			if (s.charAt(i) == ".") {
				hasdot = true;
			}
		}
	}
	if ((count == 1) && (hasdot == true)) {
		return true;
	}
	return false;
}
function chineselen(s) {
	var esclen = escape(s).length;
	var len = s.length;
	var rtnlen;
	rtnlen = ((esclen - len) / 5) * 2 + (len - (esclen - len) / 5);
	return rtnlen;
}
function getipnoto18(cardID) {
	var cardID17 = cardID.substring(0, 6) + "19" + cardID.substring(6);
	var N = 0;
	var R = -1;
	var T = "0";//储存最后一个数字 
	var j = 0;
	var v = new Array();
	var vs = "10X98765432";
	v.push(2, 4, 8, 5, 10, 9, 7, 3, 6, 1, 2, 4, 8, 5, 10, 9, 7);
	for (var i = 16; i >= 0; i--) {
		N += parseInt(cardID17.substring(i, i + 1)) * v[j];
		j++;
	}
	R = N % 11;
	T = vs.charAt(R);
	cardID18 = cardID17 + T;
	return (cardID18);
}
function getipnoto15(cardID) {
	var cardID15 = cardID.substring(0, 6) + cardID.substring(8, 17);
	return (cardID15);
}
function isNumber(oNum) {
	if (!oNum) {
		return false;
	}
	var strP = /^\d+(\.\d+)?$/;
	if (!strP.test(oNum)) {
		return false;
	}
	try {
		if (parseFloat(oNum) != oNum) {
			return false;
		}
	}
	catch (ex) {
		return false;
	}
	return true;
}